

<form action="<?php $_SERVER["PHPSELF"]; ?>" method="post">
	<table>
	<tr>
	<td>username:</td>
	<td><input type="text" size=10 value="joseph" name="username"></td>
	</tr>
	<tr>
	<td>password:</td>
	<td><input type="password" size=10 name="password"></td>
	</tr>
	</table>
	<br>	<input type="submit" name="submit">
</form>
<?php

$username = $_POST["username"] ;
$password = $_POST["password"];

if( $username )
{
	$connection = mysql_connect("localhost","root","howdy123") or exit("cannot connect to database");
	if( $connection )
		echo '<br> connection successful <br>';
	$db = mysql_select_db("db",$connection);
	
	echo "<br> username: ". $username ."<br>";
	$query = "SELECT * FROM user WHERE username = '$username'";
	$statement = mysql_query($query,$connection);

	if( $statement )
		echo "mysql query was valid. <br>";
	else
		echo "sql error: ". mysql_error(). "<br>";
	
	$results = mysql_num_rows($statement);

	if( $results <= 0)
		die("invalid username or password");

	$user_info = mysql_fetch_array($statement);

	echo "username: ". $user_info["username"] ."<br>";
	echo "user_id: ". $user_info["user_id"] ."<br>";
	echo "gender: ". $user_info["gender"] ."<br>";

	$connection = mysql_close($connection);

	if( $connection )
		echo "You are connected <br>";
	else
		die( "Invalid login");

}

?>

<a href="create_user.php"> Create a new user </a>


